package lium.lbs.lbsim.adapter

import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.buz.hjcdriver.bean.FriendsChooseResultModel
import com.buz.hjcdriver.bean.FriendsModel
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.lmlibrary.Constants
import com.qmuiteam.qmui.widget.QMUIRadiusImageView
import lium.lbs.lbsim.App
import lium.lbs.lbsim.R
import lium.lbs.lbsim.utils.PinnedHeaderItemDecoration

/**
 * 好友 adapter
 */
class ChooseFriendListtoKickAdapter
    (data: ArrayList<FriendsChooseResultModel>) :
    BaseMultiItemQuickAdapter<FriendsChooseResultModel, BaseViewHolder>(data),
    PinnedHeaderItemDecoration.PinnedHeaderAdapter {

    override fun isPinnedViewType(viewType: Int): Boolean {
        return viewType == FriendsModel.ITEM_TYPE_SETION
    }

    init {
        addItemType(FriendsModel.ITEM_TYPE_DATA, R.layout.item_contact_list_choose_kickpeople)
        addItemType(FriendsModel.ITEM_TYPE_SETION, R.layout.item_list_setion)
    }

    override fun convert(helper: BaseViewHolder?, item: FriendsChooseResultModel?) {
        helper?.let {
            item?.let {
                when (helper.itemViewType) {
                    FriendsModel.ITEM_TYPE_DATA -> {
                        initData(helper, item)
                    }
                    FriendsModel.ITEM_TYPE_SETION -> {
                        helper.getView<TextView>(R.id.item_setion).text = item.letters + ""
                    }
                }
            }
        }
    }


    private fun initData(helper: BaseViewHolder, item: FriendsChooseResultModel) {
        helper.getView<TextView>(R.id.contacts_name).text = item.nickName + ""

        val options = RequestOptions()
        Glide.with(App.getContext())
            .load(Constants.Host_Pic + item.headImage)
            .apply(options.placeholder(R.drawable.icon_defalut_head))
            .into(helper.getView<QMUIRadiusImageView>(R.id.contacts_head))

    }


}